Calculating shipping costs on `shipping.selected` event

hi there!
I’m using shipping.selected event for calculating the delivery distance from the store to the customer, then I apply some fees based on distance…

The (funny) appears using the Snipcart.api.cart.setShippingInformation method, as it triggers an expected loop, as I’m changing something that I’m listening to, so at the end I go in an infinite loop…

My question… how can I calculate the shipping fees on user shipping method selection without ending with this problem…?

Thanks!