Example 21 : Producing and sending manifests

Printer-friendly version

  When the delivery driver comes, he often requires some paperwork. The carrier will also require an electronic copy of the information (which this system delivers for you).

This example will create all the documentation and will then send the information to the carrier (HDN in this case). It should be noted that where you might think there would be only one manifest, the system might produce more. This is due to some complex rules the carriers specify and you, as the integrator, need not be concerned with. Your code, however, needs to be able to handle the situation where more than one PDF file needs to be printed, and more than one sendManifest needs to be called.

package com.metapack.dm.test;
 
import java.io.FileOutputStream;
 
import com.metapack.deliverymanager.client.webservices.ManifestService;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
 
public class Example21 extends ExampleBase {
 
	public void run() throws Exception {
		ManifestService service = createManifestService();
 
		String[] manifestCodes = service.createManifest( "HDN" , "DEFAULT" , "DELIVERY" );
 
		for( String manifestCode : manifestCodes ) {
			String encodedPdfDocument = service.createManifestAsPdf( manifestCode );
 
			/*
			 * Create the PDF document for printing
			 */
 
			byte[] rawData = Base64.decode( encodedPdfDocument );
			FileOutputStream stream = new FileOutputStream( "c:\\manifest_" + manifestCode + ".pdf" );
			stream.write( rawData );
			stream.flush();
			stream.close();
 
			/*
			 * Send the manifest electronically
			 */
 
			service.sendManifest( manifestCode );
		}
	}
}