Example 53 : Creating, finding and appending to a consignment

Printer-friendly version

This example demonstrates creating a consignment, allocating it to a carrier, producing the labels, and then adding an additional parcel.

package com.metapack.dm.test;
 
import com.metapack.deliverymanager.client.Consignment;
import com.metapack.deliverymanager.client.Parcel;
import com.metapack.deliverymanager.client.webservices.AllocationService;
import com.metapack.deliverymanager.client.webservices.ConsignmentSearchService;
import com.metapack.deliverymanager.client.webservices.ConsignmentService;
 
public class Example53 extends ExampleBase {
 
	public void run() throws Exception {
		AllocationService allocationService = createAllocationService();
		ConsignmentSearchService searchService = createConsignmentSearchService();
		ConsignmentService consignmentService = createConsignmentService();
 
		/*
		 * Create & allocate the initial consignment
		 */
 
		Consignment consignment = createDefaultConsignment( "EXAMPLE 53" , 1 );
		consignment.setConsignmentLevelDetailsFlag( false );
 
		Parcel parcel = new Parcel();
		parcel.setParcelWeight( 1.23 );
		parcel.setParcelValue( 0.56 );
		consignment.setParcels( new Parcel[] { parcel } );
 
		consignment.setParcelCount( consignment.getParcels().length );
 
		Consignment[] createdConsignments = allocationService.createAndAllocateConsignmentsWithBookingCode( new Consignment[] { consignment } , null );
		Consignment createdConsignment = createdConsignments[ 0 ];
 
		if( createdConsignment.getCarrierConsignmentCode() == null ) {
			System.out.println( "The consignment could not be allocated" );
		} else {
			System.out.println( "The consignment was allocated and a given tracking code of " + createdConsignment.getCarrierConsignmentCode() );
		}
 
		/*
		 * Show the details of what was created
		 */
 
		Consignment c = searchService.findConsignmentByConsignmentCode( createdConsignment.getConsignmentCode() );
		System.out.println( "Parcel count: " + c.getParcelCount() );
		System.out.println( "Consignment weight: " + c.getConsignmentWeight() );
		System.out.println( "Consignment value: " + c.getConsignmentValue() );
		System.out.println( "Delivery price: " + c.getShippingCost() );
 
		/*
		 * Produce the labels (so it moves to ready-to-manifest)
		 */
 
		consignmentService.createLabelsAsPdf( createdConsignment.getConsignmentCode() );
 
		/*
		 * Add another parcel to the consignment
		 */
 
		Parcel parcel2 = new Parcel();
		parcel2.setParcelWeight( 0.78 );
		parcel2.setParcelValue( 1.43 );
		consignmentService.appendParcelsToConsignment( createdConsignment.getConsignmentCode() , new Parcel[] { parcel2 } );
 
		System.out.println( "A parcel was added to " + createdConsignment.getConsignmentCode() );
 
		/*
		 * Show the amended details
		 */
 
		c = searchService.findConsignmentByConsignmentCode( createdConsignment.getConsignmentCode() );
		System.out.println( "Parcel count: " + c.getParcelCount() );
		System.out.println( "Consignment weight: " + c.getConsignmentWeight() );
		System.out.println( "Consignment value: " + c.getConsignmentValue() );
		System.out.println( "Delivery price: " + c.getShippingCost() );
	}
}