Example 14 : Searching for delivery options meeting a specific delivery date

Printer-friendly version

 This will find the services capable of delivering the consignment. In this example, we've chosen to specify the selection criteria using a filter. We've said that it is acceptable to collect it on the 19th February 2009. The services will be sorted so that the earliest collections appear first, and the cheapest comes first on each of those collection days.

package com.metapack.dm.test;
 
import com.metapack.deliverymanager.client.AllocationFilter;
import com.metapack.deliverymanager.client.Consignment;
import com.metapack.deliverymanager.client.DateRange;
import com.metapack.deliverymanager.client.DeliveryOption;
import com.metapack.deliverymanager.client.webservices.AllocationService;
 
public class Example14 extends ExampleBase {
 
	public void run() throws Exception {
		AllocationService service = createAllocationService();
 
		Consignment consignment = createDefaultConsignment( "EXAMPLE-14" , 1 );
 
		DateRange acceptableDeliverySlot = new DateRange( 
				createDate( "2009-02-19T00:00:00" ) , 
				createDate( "2009-02-19T23:59:59" ) );
 
		AllocationFilter filter = new AllocationFilter();
		filter.setFirstCollectionOnly( true );
		filter.setAcceptableDeliverySlots( new DateRange[] { acceptableDeliverySlot } );
		filter.setPreFilterSortOrder1( ExampleBase.SORT_EARLIEST_COLLECTION_ASCENDING );
		filter.setFilterGroup1( ExampleBase.FILTER_GROUP_SERVICE );
		filter.setSortOrder1( ExampleBase.SORT_EARLIEST_COLLECTION_DAY_ASCENDING );
		filter.setSortOrder2( ExampleBase.SORT_COST_CHEAPEST );
 
		DeliveryOption[] options = service.findDeliveryOptions( consignment , filter );
 
		for( DeliveryOption option : options ) {
			System.out.println( "Service " + option.getCarrierServiceCode() 
					+ " can deliver it and it will cost " + option.getCost() 
					+ " collection between " + formatDateRangeNice( option.getCollectionWindow() )
					+ " and delivery between " + formatDateRangeNice( option.getDeliveryWindow() )
			);
		}
	}
}