Example 22 : Tracking parcels within an order
After a consignment has been manifested, it moves into the Tracking state. This example demonstrates how to retrieve the tracking information about all parcels associated with an order.
The code field on the ParcelTrackingInfo object is that the customer can use in the carrier's on-line tracking site (if there is one).
package com.metapack.dm.test; import com.metapack.deliverymanager.client.ConsignmentTrackingInfo; import com.metapack.deliverymanager.client.ParcelTrackingInfo; import com.metapack.deliverymanager.client.ParcelTrackingItem; import com.metapack.deliverymanager.client.webservices.ConsignmentTrackingService; public class Example22 extends ExampleBase { public void run() throws Exception { ConsignmentTrackingService service = createConsignmentTrackingService(); ConsignmentTrackingInfo[] consignmentTrackingInfos = service.findParcelTrackingByOrderReference( "T040801-2" ); /* * Remember: more than one consignment can be tracked against a single order reference. We will * therefore iterate over each of the consignments found. */ System.out.println( "There are " + consignmentTrackingInfos.length + " consignments associated with that order number" ); for( ConsignmentTrackingInfo consignmentTrackingInfo : consignmentTrackingInfos ) { System.out.println( "================" ); System.out.println( "Consignment " + consignmentTrackingInfo.getConsignmentCode() + " is known to the carrier as " + consignmentTrackingInfo.getCarrierConsignmentCode() ); /* * Now we will identify the current status of each parcel within this consignment. */ for( ParcelTrackingInfo parcelTrackingInfo : consignmentTrackingInfo.getParcels() ) { System.out.println( " " + parcelTrackingInfo.getCode() + " is " + parcelTrackingInfo.getParcelStatusName() ); /* * For completeness, we will now show the history of all the stages this parcel has gone * through. */ for( ParcelTrackingItem parcelTrackingItem : parcelTrackingInfo.getItems() ) { System.out.println( " " + parcelTrackingItem.getParcelStatusName() + " achieved at " + formatDateTimeNice( parcelTrackingItem.getAcheivedDateTime() ) ); } } } } }

