To manage multiple trips and to use PC*MILER route options and features for each trip, you must build a trip using a sequence like the one below. It calculates mileage for a trip with multiple stops, and it optimizes the stop sequence to get the most efficient route:
1. Open a connection to the engine (PCMSOpenServer).
2. Create a new trip with PCMSNewTripWithRegion and reuse it, if possible, for future trips. If PC*MILER Worldwide data is installed you can create trips with another region.
TIP: Trips are thread safe so multiple threads can be created but do not share the trips across multiple threads. Create a number of trips and threads that match the number of CPUs. That is, an 8-CPU system should have 8 threads and one unique trip per thread.
3. Set the route type to use the PRACTICAL routing calculation (PCMSSetCalcTypeEx).
4. Set the unit of distance to MILES (PCMSSetMiles).
5. Clear stops from previous trip—use whenever multiple trips are generated (PCMSClearStops).
6. Validate stop names (PCMSLookUp with option 5).
7. Optionally use PCMSGetFmtMatch4 to get lat/longs with 6-digit precision.
8. Add a batch of stops to the trip’s route (PCMSAddStop).
9. Set the resequence mode to keep the final destination of the route the same (PCMSSetResequence).
10. (Optional) Optimize the stop sequence (PCMSOptimize).
11. Calculate a route and distances (PCMSCalculate).
12. Delete the trip (PCMSDeleteTrip).
14. Close down the engine (PCMSCloseServer).