Example 68 : Voiding a consignment
This example shows how to void a particular consignment.
package com.metapack.dm.test; import com.metapack.deliverymanager.client.Consignment; import com.metapack.deliverymanager.client.ConsignmentActionResult; import com.metapack.deliverymanager.client.webservices.AllocationService; import com.metapack.deliverymanager.client.webservices.ConsignmentService; public class Example68 extends ExampleBase { public void run() throws Exception { ConsignmentService consignmentService = createConsignmentService(); AllocationService allocationService = createAllocationService(); // First, lets create a consignment and print its labels so we have something to void Consignment exampleConsignment = createDefaultConsignment( "Example-68" , 2 ); Consignment[] createdConsignments = allocationService.createAndAllocateConsignments( new Consignment[] { exampleConsignment } , null ); String consignmentCode = createdConsignments[0].getConsignmentCode(); consignmentService.createPdfsForConsignments( new String[] { consignmentCode } ); /* * Assuming all that went fine, the consignment will now be in ready-to-manifest, so we can void it. * In this example, I'm also providing a consignment code that I know does not exist. This will * demonstrate how you see errors. */ String[] consignmentCodesToVoid = new String[] { consignmentCode, "DMC-INVALID" }; ConsignmentActionResult[] results = consignmentService.voidConsignments( consignmentCodesToVoid , "USERERROR" , "Label destroyed" ); for( ConsignmentActionResult result : results ) { if( result.getErrorCode() == null ) { System.out.println( result.getConsignmentCode() + " was voided successfully" ); } else { System.out.println( result.getConsignmentCode() + " was not voided due to error: " + result.getText() + " (" + result.getErrorCode() + ")" ); } } } public static void main(String[] args ){ Example68 ex = new Example68(); try { ex.run(); } catch( Exception e ) { e.printStackTrace(); } } }

