Example 06 : Creating and allocating a consignment using a filter

Printer-friendly version

 This will create a single consignment and allocate it to a carrier. It will respect the filter provided.

 

package com.metapack.dm.test;
 
import java.util.Calendar;
 
import com.metapack.deliverymanager.client.AllocationFilter;
import com.metapack.deliverymanager.client.Consignment;
import com.metapack.deliverymanager.client.DateRange;
import com.metapack.deliverymanager.client.webservices.AllocationService;
 
public class Example6 extends ExampleBase {
 
	public void run() throws Exception {
		AllocationService service = createAllocationService();
		Consignment consignment = createDefaultConsignment( "EXAMPLE-6" , 1 );
 
		DateRange acceptableCollectionSlot = new DateRange( Calendar.getInstance() , 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 );
 
		Consignment[] createdConsignments = service.createAndAllocateConsignments( new Consignment[] { consignment } , filter );
		Consignment createdConsignment = createdConsignments[ 0 ];
 
		if( createdConsignment.getCarrierConsignmentCode() == null ) {
			System.out.println( "Consignment " + createdConsignment.getConsignmentCode() 
					+ " could not be allocated" );
		} else {
			System.out.println( "Consignment " + createdConsignment.getConsignmentCode() 
					+ " was allocated and a given tracking code of " 
					+ createdConsignment.getCarrierConsignmentCode() );
		}
	}
}