package xml; import java.io.*; import java.net.*; /** * HTTP Post Interface Model * * @version 2.0.0.0 * @copyright eShippers, Inc. */ public class Client { private URL url; private URLConnection urlConn; private DataOutputStream xmlRequest; private BufferedReader xmlResponse; private String encodingType = "UTF-8"; private String requestParameters = ""; public Client() { try { // Specify The Name And Path Of Remote Program url = new URL("http://www.intershipper.com/Interface/Intershipper/XML/v2.0/HTTP.jsp"); // Establish A URL Connection And Set Parameters urlConn = url.openConnection(); urlConn.setDoInput(true); urlConn.setDoOutput(true); urlConn.setUseCaches(false); urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // Build Request String Via Key/Value Pairs requestParameters = "Version=" + URLEncoder.encode("2.0.0.0", encodingType) + "&ShipmentID=" + URLEncoder.encode("1234", encodingType) + "&QueryID=" + URLEncoder.encode("YourQueryCode", encodingType) + "&Username=" + URLEncoder.encode("YourUsername", encodingType) + "&Password=" + URLEncoder.encode("YourPassword", encodingType) + "&TotalCarriers=" + URLEncoder.encode("2", encodingType) + "&CarrierCode1=" + URLEncoder.encode("UPS", encodingType) + "&CarrierAccount1=" + URLEncoder.encode("123456789", encodingType) + "&CarrierInvoiced1=" + URLEncoder.encode("1", encodingType) + "&CarrierCode2=" + URLEncoder.encode("FDX", encodingType) + "&CarrierAccount2=" + URLEncoder.encode("", encodingType) + "&CarrierInvoiced2=" + URLEncoder.encode("0", encodingType) + "&TotalClasses=" + URLEncoder.encode("3", encodingType) + "&ClassCode1=" + URLEncoder.encode("1DY", encodingType) + "&ClassCode2=" + URLEncoder.encode("2DY", encodingType) + "&ClassCode3=" + URLEncoder.encode("GND", encodingType) + "&DeliveryType=" + URLEncoder.encode("COM", encodingType) + "&ShipMethod=" + URLEncoder.encode("DRP", encodingType) + "&OriginationName=" + URLEncoder.encode("John Smith", encodingType) + "&OriginationAddress1=" + URLEncoder.encode("123 Maple Lane", encodingType) + "&OriginationAddress2=" + URLEncoder.encode("", encodingType) + "&OriginationAddress3=" + URLEncoder.encode("", encodingType) + "&OriginationCity=" + URLEncoder.encode("Phoenix", encodingType) + "&OriginationState=" + URLEncoder.encode("AZ", encodingType) + "&OriginationPostal=" + URLEncoder.encode("85345", encodingType) + "&OriginationCountry=" + URLEncoder.encode("US", encodingType) + "&DestinationName=" + URLEncoder.encode("Jane Doe", encodingType) + "&DestinationAddress1=" + URLEncoder.encode("789 Oak Drive", encodingType) + "&DestinationAddress2=" + URLEncoder.encode("Suite #410", encodingType) + "&DestinationAddress3=" + URLEncoder.encode("Attention: Sales Department", encodingType) + "&DestinationCity=" + URLEncoder.encode("Tempe", encodingType) + "&DestinationState=" + URLEncoder.encode("AZ", encodingType) + "&DestinationPostal=" + URLEncoder.encode("85282", encodingType) + "&DestinationCountry=" + URLEncoder.encode("US", encodingType) + "&Currency=" + URLEncoder.encode("USD", encodingType) + "&TotalPackages=" + URLEncoder.encode("2", encodingType) + "&BoxID1=" + URLEncoder.encode("YourBoxCode1", encodingType) + "&Weight1=" + URLEncoder.encode("10", encodingType) + "&WeightUnit1=" + URLEncoder.encode("LB", encodingType) + "&Length1=" + URLEncoder.encode("10", encodingType) + "&Width1=" + URLEncoder.encode("10", encodingType) + "&Height1=" + URLEncoder.encode("10", encodingType) + "&DimensionalUnit1=" + URLEncoder.encode("IN", encodingType) + "&Packaging1=" + URLEncoder.encode("BOX", encodingType) + "&Contents1=" + URLEncoder.encode("OTR", encodingType) + "&Cod1=" + URLEncoder.encode("18500", encodingType) + "&Insurance1=" + URLEncoder.encode("15000", encodingType) + "&BoxID2=" + URLEncoder.encode("YourBoxCode2", encodingType) + "&Weight2=" + URLEncoder.encode("20", encodingType) + "&WeightUnit2=" + URLEncoder.encode("LB", encodingType) + "&Length2=" + URLEncoder.encode("20", encodingType) + "&Width2=" + URLEncoder.encode("20", encodingType) + "&Height2=" + URLEncoder.encode("20", encodingType) + "&DimensionalUnit2=" + URLEncoder.encode("IN", encodingType) + "&Packaging2=" + URLEncoder.encode("BOX", encodingType) + "&Contents2=" + URLEncoder.encode("OTR", encodingType) + "&Cod2=" + URLEncoder.encode("0", encodingType) + "&Insurance2=" + URLEncoder.encode("0", encodingType) + "&TotalOptions=" + URLEncoder.encode("3", encodingType) + "&OptionCode1=" + URLEncoder.encode("ADD", encodingType) + "&OptionCode2=" + URLEncoder.encode("PDD", encodingType) + "&OptionCode3=" + URLEncoder.encode("SDD", encodingType); // Send Request To Quote Engine Via HTTP Post xmlRequest = new DataOutputStream(urlConn.getOutputStream()); xmlRequest.writeBytes(requestParameters); xmlRequest.flush(); xmlRequest.close(); // Get XML-Formatted Response From Quote Engine xmlResponse = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); // Handle XML-Formatted Response As Necessary String token = xmlResponse.readLine(); while (token != null) { System.out.println(token); token = xmlResponse.readLine(); } // Close Input Stream To Finalize Transaction xmlResponse.close(); } catch (MalformedURLException me) { System.err.println("MalformedURLException: " + me); } catch (IOException ioe) { System.err.println("IOException: " + ioe.getMessage()); } } }