Example 13 : Searching for delivery options using a filter
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 after the 14th February 2009. We will only consider the first possible collections of each service (this is an optimisation technique), and ordering the results so the cheapest comes first.
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 Example13 extends ExampleBase { public void run() throws Exception { AllocationService service = createAllocationService(); Consignment consignment = createDefaultConsignment( "EXAMPLE-13" , 1 ); DateRange acceptableCollectionSlot = new DateRange( createDate( "2009-02-14T00:00:00" ) , null ); AllocationFilter filter = new AllocationFilter(); filter.setFirstCollectionOnly( true ); filter.setAcceptableCollectionSlots( new DateRange[] { acceptableCollectionSlot } ); filter.setPreFilterSortOrder1( ExampleBase.SORT_EARLIEST_COLLECTION_ASCENDING ); filter.setFilterGroup1( ExampleBase.FILTER_GROUP_SERVICE ); filter.setSortOrder1( 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() ) ); } } }

