How to stop a route early?

Is there a way to end a route early after you have met a certain condition?

For example,
A vehicle collects both Apples and Bananas. When the vehicle has collected all the Bananas the route is over and it doesn’t matter how many Apples are left.