一、UPS:
import java.io.ByteArrayInputStream;
import java.util.Iterator;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.xpath.XPath;
public class UPS
{
private String AccessLicenseNumber;
private String UserID;
private String Password;
private String pickuptypecode;
private String customerclassification;
private String packagingtypecode;
private String shippernumber;
private String residentialaddressindicator;
private String largepackageindicator;
public UPS()
{
this.AccessLicenseNumber = "Your AccessLicenseNumber";
this.UserID = "UserID";
this.Password = "123456";
this.pickuptypecode = "01";
this.customerclassification = "04";
this.packagingtypecode = "02";
this.shippernumber = "";
this.residentialaddressindicator = "";
this.largepackageindicator = "";
}
@SuppressWarnings("unchecked")
public String ups_string(String receivercity, String receiverstateprovincecode, String receiverpostalcode,
String receivercountrycode, String shipmentweight,
String shippercity,
String shipperstateprovincecode,
String shipperpostalcode,
String shippercountrycode)
{
try
{
String strXML = "";
String ups_desc = "";
strXML = "<?xml version='1.0'?><AccessRequest xml:lang='en-US'><AccessLicenseNumber>"
+ this.AccessLicenseNumber + "</AccessLicenseNumber>";
strXML = strXML + "<UserId>" + this.UserID + "</UserId><Password>" + this.Password
+ " </Password></AccessRequest><?xml version='1.0'?>";
strXML = strXML + "<RatingServiceSelectionRequest xml:lang='en-US'>";
strXML = strXML
+ "<Request><TransactionReference><CustomerContext>Rating and Service</CustomerContext><XpciVersion>1.0001</XpciVersion></TransactionReference>";
strXML = strXML + "<RequestAction>Rate</RequestAction>";
strXML = strXML + "<RequestOption>shop</RequestOption></Request>";
strXML = strXML + "<PickupType><Code>" + this.pickuptypecode + "</Code></PickupType>";
strXML = strXML + "<CustomerClassification><Code>" + this.customerclassification
+ "</Code></CustomerClassification>";
strXML = strXML + "<Shipment><Shipper>";
if (!this.shippernumber.trim().equals(""))
{
strXML = strXML + "<ShipperNumber>" + this.shippernumber + "</ShipperNumber>";
}
strXML = strXML + "<Address>";
strXML = strXML + "<city>" + shippercity + "</city>";
strXML = strXML + "<StateProvinceCode>" + shipperstateprovincecode + "</StateProvinceCode>";
strXML = strXML + "<PostalCode>" + shipperpostalcode + "</PostalCode>";
strXML = strXML + "<CountryCode>" + shippercountrycode + "</CountryCode>";
strXML = strXML + "</Address>";
strXML = strXML + "</Shipper>";
strXML = strXML + "<ShipTo><Address>";
strXML = strXML + "<city>" + receivercity + "</city>";
strXML = strXML + "<StateProvinceCode>" + receiverstateprovincecode + "</StateProvinceCode>";
strXML = strXML + "<PostalCode>" + receiverpostalcode + "</PostalCode>";
strXML = strXML + "<CountryCode>" + receivercountrycode + "</CountryCode>";
if (!this.residentialaddressindicator.trim().equals(""))
{
strXML = strXML + "<ResidentialAddressIndicator></ResidentialAddressIndicator>";
}
strXML = strXML + "</Address></ShipTo>";
strXML = strXML + "<Service><Code>" + "11" + "</Code></Service>";
strXML = strXML + "<Package><PackagingType><Code>" + this.packagingtypecode + "</Code>";
strXML = strXML + "<Description>Package</Description></PackagingType>";
strXML = strXML + "<Description>Rate Shopping</Description>";
strXML = strXML + "<PackageWeight><Weight>" + shipmentweight + "</Weight></PackageWeight>";
if (!this.largepackageindicator.trim().equals(""))
{
strXML = strXML + "<LargePackageIndicator>1</LargePackageIndicator>";
}
strXML = strXML + "</Package>";
strXML = strXML + "<ShipmentServiceOptions>" + ""
+ "</ShipmentServiceOptions></Shipment></RatingServiceSelectionRequest>";
WishBrowser wb = new WishBrowser("
wb.setCharSet("utf-8");
String result = "";
String strFile = wb.sendXmlRequest(strXML);
ByteArrayInputStream bis = new ByteArrayInputStream(strFile.getBytes());
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(bis);
XPath compPath = XPath.newInstance("http://RatedShipment");
List compbackup = compPath.selectNodes(doc);
if (!compbackup.isEmpty())
{
Iterator t = compbackup.iterator();
ups_desc = "";
while (t.hasNext())
{
Element eComplateBackup = (Element) t.next();
String code = eComplateBackup.getChild("Service").getChildText("Code");
String monetaryValue = eComplateBackup.getChild("TotalCharges").getChildText("MonetaryValue");
String guaranteedDaysToDelivery = eComplateBackup.getChild("GuaranteedDaysToDelivery")
.getTextTrim();
// 運送方式
if (code.equals("01"))
ups_desc = "UPS Next Day Air.";
else if (code.equals("02"))
ups_desc = "UPS 2nd Day Air.";
else if (code.equals("03"))
ups_desc = "UPS Ground";
else if (code.equals("07"))
ups_desc = "UPS Worldwide ExpressSM";
else if (code.equals("08"))
ups_desc = "UPS Worldwide ExpeditedSM ";
else if (code.equals("11"))
ups_desc = "UPS Standard UPS";
else if (code.equals("12"))
ups_desc = "UPS 3 Day Select";
else if (code.equals("13"))
ups_desc = "UPS Next Day Air Saver";
else if (code.equals("14"))
ups_desc = "UPS Next Day Air. Early A.M.";
else if (code.equals("54"))
ups_desc = "UPS Worldwide Express PlusSM";
else if (code.equals("59"))
ups_desc = "UPS 2nd Day Air A.M.";
// 到貨天數
if (!guaranteedDaysToDelivery.equals(""))
{
int days = Integer.parseInt(guaranteedDaysToDelivery);
if (days > 1)
{
ups_desc = ups_desc + " - " + days + " days";
}
else
{
ups_desc = ups_desc + " - " + days + " day";
}
}
// 價格
if (result.equals(""))
{
result = result + "$" + monetaryValue + "|" + ups_desc;
}
else
{
result = result + "WISH_DELIM" + "$" + monetaryValue + "|" + ups_desc;
}
}
}
System.out.println("THE UPS STRING IS:" + result);
return result;
}
catch(Exception e)
{
System.out.println("GET UPS STRING ERROR");
return "";
}
}
public String getAccessLicenseNumber()
{
return AccessLicenseNumber;
}
public void setAccessLicenseNumber(String accessLicenseNumber)
{
AccessLicenseNumber = accessLicenseNumber;
}
public String getUserID()
{
return UserID;
}
public void setUserID(String userID)
{
UserID = userID;
}
public String getPassword()
{
return Password;
}
public void setPassword(String password)
{
Password = password;
}
public String getPickuptypecode()
{
return pickuptypecode;
}
public void setPickuptypecode(String pickuptypecode)
{
this.pickuptypecode = pickuptypecode;
}
public String getCustomerclassification()
{
return customerclassification;
}
public void setCustomerclassification(String customerclassification)
{
this.customerclassification = customerclassification;
}
public String getPackagingtypecode()
{
return packagingtypecode;
}
public void setPackagingtypecode(String packagingtypecode)
{
this.packagingtypecode = packagingtypecode;
}
public String getShippernumber()
{
return shippernumber;
}
public void setShippernumber(String shippernumber)
{
this.shippernumber = shippernumber;
}
public String getResidentialaddressindicator()
{
return residentialaddressindicator;
}
public void setResidentialaddressindicator(String residentialaddressindicator)
{
this.residentialaddressindicator = residentialaddressindicator;
}
public String getLargepackageindicator()
{
return largepackageindicator;
}
public void setLargepackageindicator(String largepackageindicator)
{
this.largepackageindicator = largepackageindicator;
}
}
二、FEDEX
package com.wish.eggtion.shipping;
import java.io.ByteArrayInputStream;
import java.util.Iterator;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.xpath.XPath;
public class FEDEX
{
private String fedex_url;
private String AccountNumber;
private String MeterNumber;
private String ShipDate;
private String DropoffType;
private String Packaging;
private String WeightUnits; this.AccountNumber = "123456789"; this.MeterNumber = "123456"; this.ShipDate = ""; this.DropoffType = ""; this.Packaging = ""; this.WeightUnits = ""; @SuppressWarnings("unchecked") String r_service = ""; strXML = "<?xml version='1.0' encoding='UTF-8' ?>" if (Double.parseDouble(DeclaredValue) > 0) WishBrowser wb = new WishBrowser(this.fedex_url); ByteArrayInputStream bis = new ByteArrayInputStream(strFile.getBytes()); SAXBuilder builder = new SAXBuilder(); XPath compPath = XPath.newInstance("http://Error"); SAXBuilder builder_e = new SAXBuilder(); XPath compPath_e = XPath.newInstance("http://Entry"); public String getFedex_url() public void setFedex_url(String fedex_url) public String getAccountNumber() public void setAccountNumber(String accountNumber) public String getMeterNumber() public void setMeterNumber(String meterNumber) public String getShipDate() public void setShipDate(String shipDate) public String getDropoffType() public void setDropoffType(String dropoffType) public String getPackaging() public void setPackaging(String packaging) public String getWeightUnits() public void setWeightUnits(String weightUnits) import org.jdom.Document; public class USPS private String usps_password; private String usps_container; private String usps_pkgsize; private boolean usps_machinable; private String usps_mailtype; private boolean is_canned_test; private String RESULT_uspsintl_Prohibitions; private String RESULT_uspsintl_Restrictions; this.usps_password = ""; this.usps_container = ""; this.usps_pkgsize = ""; this.usps_machinable = false; this.usps_mailtype = ""; this.is_canned_test = false; this.RESULT_uspsintl_Prohibitions = ""; this.RESULT_uspsintl_Restrictions = ""; @SuppressWarnings("unchecked") WishBrowser wb = new WishBrowser(this.xml_dest); ByteArrayInputStream bis = new ByteArrayInputStream(strFile.getBytes()); SAXBuilder builder = new SAXBuilder(); XPath compPath = XPath.newInstance("http://Error"); SAXBuilder builder_e = new SAXBuilder(); XPath compPath_e = XPath.newInstance("http://Package//Error"); XPath compPath_e_e = XPath.newInstance("http://Package//Postage"); @SuppressWarnings("unchecked") WishBrowser wb = new WishBrowser(xml_dest); String strFile = wb.sendXmlRequest(strXML); SAXBuilder builder = new SAXBuilder(); XPath compPath = XPath.newInstance("http://Error"); SAXBuilder builder_e = new SAXBuilder(); XPath compPath_e = XPath.newInstance("http://Package//Service"); SAXBuilder builder_e_i = new SAXBuilder(); XPath compPath_e_i = XPath.newInstance("http://Package"); public String getUsps_userid() public void setUsps_userid(String usps_userid) public String getUsps_password() public void setUsps_password(String usps_password) public String getUsps_container() public void setUsps_container(String usps_container) public String getUsps_pkgsize() public void setUsps_pkgsize(String usps_pkgsize) public boolean isUsps_machinable() public void setUsps_machinable(boolean usps_machinable) public String getUsps_mailtype() public void setUsps_mailtype(String usps_mailtype) public boolean isIs_canned_test() public void setIs_canned_test(boolean is_canned_test) public String getRESULT_uspsintl_Prohibitions() public void setRESULT_uspsintl_Prohibitions(String prohibitions) public String getRESULT_uspsintl_Restrictions() public void setRESULT_uspsintl_Restrictions(String restrictions) public String getXml_dest() public void setXml_dest(String xml_dest) 四、Shipping. private boolean USPS_ENABLED; this.USPS_ENABLED = true; String DeclaredValue = "0"; // UPS if (!fedex_fdxe_shipping_options.trim().equals("")) if (!fedex_fdxg_shipping_options.trim().equals("")) boolean skip_usps_domestic = false; // USPS if (USPSINTL_ENABLED shipping_options = shipping_options.replaceAll("\"", ""); // REMOVE UNWANTED OPTIONS BASED ON FILTER LIST public String getShipperstateprovincecode() public void setShipperstateprovincecode(String shipperstateprovincecode) public String getShipperpostalcode() public void setShipperpostalcode(String shipperpostalcode) public String getShippercountrycode() public void setShippercountrycode(String shippercountrycode) public String getShippercity() public void setShippercity(String shippercity) public boolean isUSPS_ENABLED() public void setUSPS_ENABLED(boolean usps_enabled) public boolean isFEDEX_FDXE_ENABLED() public void setFEDEX_FDXE_ENABLED(boolean fedex_fdxe_enabled) public boolean isFEDEX_FDXG_ENABLED() public void setFEDEX_FDXG_ENABLED(boolean fedex_fdxg_enabled) public boolean isUPS_ENABLED() public void setUPS_ENABLED(boolean ups_enabled) public boolean isUSPSINTL_ENABLED() public void setUSPSINTL_ENABLED(boolean uspsintl_enabled) public boolean isSHOW_UPS_ERROR() public void setSHOW_UPS_ERROR(boolean show_ups_error) public boolean isSHOW_FEDEX_ERROR() public void setSHOW_FEDEX_ERROR(boolean show_fedex_error) public boolean isSHOW_USPS_ERROR()
public FEDEX()
{
this.fedex_url = "
}
public String fedex_string(String CarrierCode, String Weight, String DeclaredValue,
String receiverstateprovincecode, String receiverpostalcode, String receivercountrycode,
String shipperstateprovincecode, String shipperpostalcode, String shippercountrycode)
{
try
{
String strXML = "";
String str_result = "";
String r_deliverydate = "";
String r_NetCharge = "";
String r_value = "";
String r_caption = "";
+ "<FDXRateAvailableServicesRequest xmlns:api='http://www.fedex.com/fsmapi' "
+ "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
+ "xsi:noNamespaceSchemaLocation='FDXRateAvailableServicesRequest.xsd'>" + "<RequestHeader>"
+ "<CustomerTransactionIdentifier>Your_Own_TrnID</CustomerTransactionIdentifier>"
+ " <AccountNumber>"
+ this.AccountNumber
+ "</AccountNumber>"
+ " <MeterNumber>"
+ this.MeterNumber
+ "</MeterNumber>"
+ " <CarrierCode>"
+ CarrierCode
+ "</CarrierCode>"
+ "</RequestHeader>"
+ "<ShipDate>"
+ this.ShipDate
+ "</ShipDate>"
+ "<DropoffType>"
+ this.DropoffType
+ "</DropoffType>"
+ "<Packaging>"
+ this.Packaging
+ "</Packaging>"
+ "<WeightUnits>"
+ this.WeightUnits
+ "</WeightUnits>" + "<Weight>" + Weight + "</Weight>";
strXML = strXML + "<DeclaredValue><Value>" + DeclaredValue + "</Value></DeclaredValue>";
strXML = strXML + "<ListRate>false</ListRate>" + "<OriginAddress>" + " <StateOrProvinceCode>"
+ shipperstateprovincecode + "</StateOrProvinceCode>" + " <PostalCode>" + shipperpostalcode
+ "</PostalCode>" + " <CountryCode>" + shippercountrycode + "</CountryCode>" + "</OriginAddress>"
+ "<DestinationAddress>" + " <StateOrProvinceCode>" + receiverstateprovincecode
+ "</StateOrProvinceCode>" + " <PostalCode>" + receiverpostalcode + "</PostalCode>"
+ " <CountryCode>" + receivercountrycode + "</CountryCode>" + "</DestinationAddress>" + "<Payment>"
+ " <PayorType>SENDER</PayorType>" + "</Payment>" + "<PackageCount>1</PackageCount>"
+ "</FDXRateAvailableServicesRequest>";
wb.setCharSet("utf-8");
String strFile = wb.sendXmlRequest(strXML);
Document doc = builder.build(bis);
List compbackup = compPath.selectNodes(doc);
if (!compbackup.isEmpty())
{
str_result = "";
Iterator t = compbackup.iterator();
Element eComplateBackup = (Element) t.next();
String error = eComplateBackup.getChildText("Message");
str_result = "0|FEDEX ERROR: " + error;
str_result = ""; // 如果發生異常,則不顯示該公司配貨相關信息
}
else
{
ByteArrayInputStream bis_e = new ByteArrayInputStream(strFile.getBytes());
Document doc_e = builder_e.build(bis_e);
List entry = compPath_e.selectNodes(doc_e);
if (!entry.isEmpty())
{
Iterator t = entry.iterator();
while (t.hasNext())
{
Element ent = (Element) t.next();
r_service = ent.getChildText("Service");
if (CarrierCode.equals("FDXE"))
{
r_deliverydate = ent.getChildText("DeliveryDay");
r_deliverydate = r_deliverydate + " " + ent.getChildText("DeliveryDate");
}
else
{
r_deliverydate = ent.getChildText("TimeInTransit") + " day";
}
r_NetCharge = ent.getChild("EstimatedCharges").getChild("DiscountedCharges").getChildText(
"NetCharge");
r_value = r_NetCharge;
r_caption = "FEDEX " + r_service;
if (!r_deliverydate.equals(""))
{
r_caption = r_caption + " - " + r_deliverydate;
}
if (str_result.equals(""))
{
str_result = "$" + r_value + "|" + r_caption;
}
else
{
str_result = str_result + "WISH_DELIM" + "$" + r_value + "|" + r_caption;
}
}
}
}
System.out.println("THE FEDEX STRING IS:" + str_result);
return str_result;
}
catch (Exception e)
{
System.out.println("GET FEDEX STRING ERROR");
return "";
}
}
{
return fedex_url;
}
{
this.fedex_url = fedex_url;
}
{
return AccountNumber;
}
{
AccountNumber = accountNumber;
}
{
return MeterNumber;
}
{
MeterNumber = meterNumber;
}
{
return ShipDate;
}
{
ShipDate = shipDate;
}
{
return DropoffType;
}
{
DropoffType = dropoffType;
}
{
return Packaging;
}
{
Packaging = packaging;
}
{
return WeightUnits;
}
{
WeightUnits = weightUnits;
}
}
三、USPS
package com.wish.eggtion.shipping;
import java.io.ByteArrayInputStream;
import java.util.Iterator;
import java.util.List;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.xpath.XPath;
{
private String usps_userid;
private String xml_dest;
public USPS()
{
this.usps_userid = "123456789";
this.xml_dest = "
}
public String usps_string(String receiverpostalcode, String shipmentweight,
String shipperpostalcode)
{
try
{
String str_result = "";
float weight_in_ounces = Float.parseFloat(shipmentweight) * 16;
String strXML = "API=RateV2&XML=<RateV2Request " + "USERID='" + this.usps_userid + "' PASSWORD='"
+ this.usps_password + "'>" + "<Package ID='0'>" + "<Service>All</Service>" + "<ZipOrigination>"
+ shipperpostalcode + "</ZipOrigination>" + "<ZipDestination>" + receiverpostalcode
+ "</ZipDestination>" + "<Pounds>0</Pounds>" + "<Ounces>" + weight_in_ounces + " </Ounces>"
+ "<Container>" + this.usps_container + "</Container>" + "<Size>" + this.usps_pkgsize + "</Size>"
+ "<Machinable>" + this.usps_machinable + "</Machinable>" + "</Package></RateV2Request>";
wb.setCharSet("utf-8");
String strFile = wb.sendXmlRequest(strXML);
Document doc = builder.build(bis);
List compbackup = compPath.selectNodes(doc);
if (!compbackup.isEmpty())
{
str_result = "";
Iterator t = compbackup.iterator();
Element eComplateBackup = (Element) t.next();
String error = eComplateBackup.getChildText("Description");
str_result = "0|USPS ERROR: " + error;
str_result = ""; // 如果發生異常,則不顯示該公司配貨相關信息
}
else
{
ByteArrayInputStream bis_e = new ByteArrayInputStream(strFile.getBytes());
Document doc_e = builder_e.build(bis_e);
List list = compPath_e.selectNodes(doc_e);
if (list.size() >= 1)
{
Element ent = (Element) list.get(0);
str_result = "0|USPS Error: " + ent.getChildText("Description");
str_result = "";
}
else
{
ByteArrayInputStream bis_e_e = new ByteArrayInputStream(strFile.getBytes());
SAXBuilder builder_e_e = new SAXBuilder();
Document doc_e_e = builder_e_e.build(bis_e_e);
List list_e = compPath_e_e.selectNodes(doc_e_e);
if (!list_e.isEmpty())
{
str_result = "";
Iterator t = list_e.iterator();
while (t.hasNext())
{
Element ent = (Element) t.next();
str_result = str_result + "WISH_DELIM";
str_result = str_result + ent.getChildText("Rate");
str_result = str_result + "|UspsDomestic-" + ent.getChildText("MailService");
String temp = ent.getChildText("MailService").toUpperCase();
if (temp.substring(0, 13).equals("PRIORITY MAIL"))
{
str_result = str_result + " (2-3 Days)";
}
else
{
String temp_e = ent.getChildText("MailService").toUpperCase();
if (temp_e.substring(0, 12).equals("EXPRESS MAIL"))
{
str_result = str_result + " (Next Day)";
}
else
{
str_result = str_result + " (2-9 Days)";
}
}
}
}
}
}
System.out.println("THE USPS STRING IS:" + str_result);
return str_result;
}
catch (Exception e)
{
System.out.println("THE USPS STRING IS:GET USPS STRING ERROR");
return "";
}
}
public String uspsintl_string(String Country, String weight_in_pounds)
{
try
{
String strXML = "";
String xml_dest = "";
String str_result = "";
float weight_in_ounces = Float.parseFloat(weight_in_pounds) * 16;
if (is_canned_test)
{
xml_dest = "
strXML = "API=IntlRate&XML=<IntlRateRequest USERID='" + usps_userid + "' PASSWORD='" + usps_password
+ "'>" + " <Package ID='0'> " + " <Pounds>2</Pounds> " + " <Ounces>0</Ounces> "
+ " <MailType>Package</MailType> " + " <Country>Albania</Country> " + " </Package> "
+ "</IntlRateRequest>";
}
else
{
xml_dest = "
strXML = "API=IntlRate&XML=<IntlRateRequest USERID='" + usps_userid + "' PASSWORD='" + usps_password
+ "'>" + " <Package ID='0'> " + " <Pounds>0</Pounds> " + " <Ounces>" + weight_in_ounces
+ "</Ounces> " + " <MailType>" + this.usps_mailtype + "</MailType> " + " <Country>" + Country
+ "</Country> " + " </Package> " + "</IntlRateRequest>";
}
wb.setCharSet("utf-8");
ByteArrayInputStream bis = new ByteArrayInputStream(strFile.getBytes());
Document doc = builder.build(bis);
List compbackup = compPath.selectNodes(doc);
if (!compbackup.isEmpty())
{
str_result = "";
Iterator t = compbackup.iterator();
Element eComplateBackup = (Element) t.next();
String error = eComplateBackup.getChildText("Description");
str_result = "0|Usps Error: " + error;
str_result = "";
}
else
{
ByteArrayInputStream bis_e = new ByteArrayInputStream(strFile.getBytes());
Document doc_e = builder_e.build(bis_e);
List entry = compPath_e.selectNodes(doc_e);
if (!entry.isEmpty())
{
str_result = "";
Iterator t = entry.iterator();
while (t.hasNext())
{
Element ent = (Element) t.next();
str_result = str_result + ent.getChildText("Postage");
str_result = str_result + "|UspsIntl-" + ent.getChildText("SvcDescription") + " ("
+ ent.getChildText("SvcCommitments") + ")" + "WISH_DELIM";
}
ByteArrayInputStream bis_e_i = new ByteArrayInputStream(strFile.getBytes());
Document doc_e_i = builder_e_i.build(bis_e_i);
List entry_i = compPath_e_i.selectNodes(doc_e_i);
if (!entry_i.isEmpty())
{
Element ent_i = (Element) t.next();
this.RESULT_uspsintl_Prohibitions = ent_i.getChildText("Prohibitions");
this.RESULT_uspsintl_Restrictions = ent_i.getChildText("Restrictions");
}
else
{
this.RESULT_uspsintl_Prohibitions = "";
this.RESULT_uspsintl_Restrictions = "";
}
}
}
System.out.println("THE USPSINTL STRING IS:" + str_result);
return str_result;
}
catch(Exception e)
{
System.out.println("GET USPSINTL STRING ERROR");
return "";
}
}
{
return usps_userid;
}
{
this.usps_userid = usps_userid;
}
{
return usps_password;
}
{
this.usps_password = usps_password;
}
{
return usps_container;
}
{
this.usps_container = usps_container;
}
{
return usps_pkgsize;
}
{
this.usps_pkgsize = usps_pkgsize;
}
{
return usps_machinable;
}
{
this.usps_machinable = usps_machinable;
}
{
return usps_mailtype;
}
{
this.usps_mailtype = usps_mailtype;
}
{
return is_canned_test;
}
{
this.is_canned_test = is_canned_test;
}
{
return RESULT_uspsintl_Prohibitions;
}
{
RESULT_uspsintl_Prohibitions = prohibitions;
}
{
return RESULT_uspsintl_Restrictions;
}
{
RESULT_uspsintl_Restrictions = restrictions;
}
{
return xml_dest;
}
{
this.xml_dest = xml_dest;
}
}
public class Shipping
{
// 發貨人州編碼
private String shipperstateprovincecode;
// 發貨人郵政編碼
private String shipperpostalcode;
// 發貨人國家地區編碼
private String shippercountrycode;
// 發貨人城市
private String shippercity;
private boolean FEDEX_FDXE_ENABLED;
private boolean FEDEX_FDXG_ENABLED;
private boolean UPS_ENABLED;
private boolean USPSINTL_ENABLED;
private boolean SHOW_UPS_ERROR;
private boolean SHOW_FEDEX_ERROR;
private boolean SHOW_USPS_ERROR;
private String FILTER_LIST;
private UPS ups;
private FEDEX fedex;
private USPS usps;
public Shipping()
{
// 發貨人州編碼
this.shipperstateprovincecode = "";
// 發貨人郵政編碼
this.shipperpostalcode = "";
// 發貨人國家地區編碼
this.shippercountrycode = "";
// 發貨人城市
this.shippercity = "";
this.FEDEX_FDXE_ENABLED = true;
this.FEDEX_FDXG_ENABLED = true;
this.UPS_ENABLED = true;
this.USPSINTL_ENABLED = true;
this.SHOW_UPS_ERROR = true;
this.SHOW_FEDEX_ERROR = true;
this.SHOW_USPS_ERROR = true;
this.FILTER_LIST = "";
this.ups = new UPS();
this.fedex = new FEDEX();
this.usps = new USPS();
}
public String[] GET_SHIPPING_RATES(String receivercity, String receiverstateprovincecode, String receiverpostalcode,
String receivercountrycode, String receivercountryname, String shipmentweight) throws Exception
{
receivercity = receivercity.toUpperCase();
receiverstateprovincecode = receiverstateprovincecode.toUpperCase();
receivercountrycode = receivercountrycode.toUpperCase();
if (receivercountrycode.trim().equals(""))
{
receivercountrycode = "US";
}
String[] shipping_array;
String[] ship_option;
String shipping_options = "";
String ups_shipping_options ="";
String fedex_fdxe_shipping_options = "";
String fedex_fdxg_shipping_options = "";
String usps_shipping_options = "";
String uspsintl_shipping_options = "";
if (UPS_ENABLED)
{
ups_shipping_options = ups.ups_string(receivercity, receiverstateprovincecode, receiverpostalcode,
receivercountrycode, shipmentweight, shippercity, shipperstateprovincecode, shipperpostalcode,
shippercountrycode);
if (!ups_shipping_options.trim().equals(""))
{
shipping_options = ups_shipping_options;
}
}
// FEDEX
if (FEDEX_FDXE_ENABLED)
{
fedex_fdxe_shipping_options = fedex.fedex_string("FDXE", shipmentweight, DeclaredValue,
receiverstateprovincecode, receiverpostalcode, receivercountrycode, shipperstateprovincecode,
shipperpostalcode, shippercountrycode);
}
if (FEDEX_FDXG_ENABLED)
{
fedex_fdxg_shipping_options = fedex.fedex_string("FDXG", shipmentweight, DeclaredValue,
receiverstateprovincecode, receiverpostalcode, receivercountrycode, shipperstateprovincecode,
shipperpostalcode, shippercountrycode);
}
{
if (!shipping_options.trim().equals(""))
{
shipping_options = shipping_options + "WISH_DELIM"
+ fedex_fdxe_shipping_options;
}
else
{
shipping_options = fedex_fdxe_shipping_options;
}
}
{
if (!shipping_options.trim().equals(""))
{
shipping_options = shipping_options + "WISH_DELIM"
+ fedex_fdxg_shipping_options;
}
else
{
shipping_options = fedex_fdxg_shipping_options;
}
}
if (!receivercountrycode.trim().equals("")
|| !receivercountryname.trim().equals(""))
{
if (!receivercountrycode.toUpperCase().trim().equals("US")
&& !receivercountryname.toUpperCase().trim().equals("USA"))
{
skip_usps_domestic = true;
}
}
if (!skip_usps_domestic)
{
if (USPS_ENABLED)
{
usps_shipping_options = usps.usps_string(receiverpostalcode, shipmentweight, shipperpostalcode);
if (!usps_shipping_options.trim().equals(""))
{
if (!shipping_options.trim().equals(""))
{
shipping_options = shipping_options + "WISH_DELIM" + usps_shipping_options;
}
else
{
shipping_options = usps_shipping_options;
}
}
}
}
&& !receivercountrycode.toUpperCase().trim().equals("US")
&& !receivercountryname.toUpperCase().trim().equals("USA"))
{
uspsintl_shipping_options = usps.uspsintl_string(receivercountryname, shipmentweight);
if (!uspsintl_shipping_options.trim().equals(""))
{
if (!shipping_options.trim().equals(""))
{
shipping_options = shipping_options + "WISH_DELIM" + uspsintl_shipping_options;
}
else
{
shipping_options = uspsintl_shipping_options;
}
}
}
String filtered_list;
boolean exclude;
if (!FILTER_LIST.trim().equals(""))
{
shipping_array = shipping_options.split("WISH_DELIM");
String[] filter_array = FILTER_LIST.split("|");
filtered_list = "";
for (int i = 0; i < shipping_array.length; i++)
{
ship_option = shipping_array[i].split("|");
exclude = false;
for (int j = 0; j < filter_array.length; j++)
{
if (ship_option[1].trim().equals(filter_array[j]))
{
exclude = true;
break;
}
}
if (!exclude)
{
if (filtered_list.trim().equals(""))
{
filtered_list = shipping_array[i];
}
else
{
filtered_list = filtered_list + "WISH_DELIM"
+ shipping_array[i];
}
}
}
shipping_options = filtered_list;
}
return shipping_options.split("WISH_DELIM");
}
{
return shipperstateprovincecode;
}
{
this.shipperstateprovincecode = shipperstateprovincecode;
}
{
return shipperpostalcode;
}
{
this.shipperpostalcode = shipperpostalcode;
}
{
return shippercountrycode;
}
{
this.shippercountrycode = shippercountrycode;
}
{
return shippercity;
}
{
this.shippercity = shippercity;
}
{
return USPS_ENABLED;
}
{
USPS_ENABLED = usps_enabled;
}
{
return FEDEX_FDXE_ENABLED;
}
{
FEDEX_FDXE_ENABLED = fedex_fdxe_enabled;
}
{
return FEDEX_FDXG_ENABLED;
}
{
FEDEX_FDXG_ENABLED = fedex_fdxg_enabled;
}
{
return UPS_ENABLED;
}
{
UPS_ENABLED = ups_enabled;
}
{
return USPSINTL_ENABLED;
}
{
USPSINTL_ENABLED = uspsintl_enabled;
}
{
return SHOW_UPS_ERROR;
}
{
SHOW_UPS_ERROR = show_ups_error;
}
{
return SHOW_FEDEX_ERROR;
}
{
SHOW_FEDEX_ERROR = show_fedex_error;
}
{
return SHOW_USPS_ERROR;
}