一、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("https://www.ups.com/ups.app/xml/Rate?");
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("//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;
public FEDEX()
{
this.fedex_url = "https://gateway.fedex.com/GatewayDC";
this.AccountNumber = "123456789";
this.MeterNumber = "123456";
this.ShipDate = "";
this.DropoffType = "";
this.Packaging = "";
this.WeightUnits = "";
}
@SuppressWarnings("unchecked")
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_service = "";
String r_deliverydate = "";
String r_NetCharge = "";
String r_value = "";
String r_caption = "";
strXML = "<?xml version='1.0' encoding='UTF-8' ?>"
+ "<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>";
if (Double.parseDouble(DeclaredValue) > 0)
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>";
WishBrowser wb = new WishBrowser(this.fedex_url);
wb.setCharSet("utf-8");
String strFile = wb.sendXmlRequest(strXML);
ByteArrayInputStream bis = new ByteArrayInputStream(strFile.getBytes());
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(bis);
XPath compPath = XPath.newInstance("//Error");
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());
SAXBuilder builder_e = new SAXBuilder();
Document doc_e = builder_e.build(bis_e);
XPath compPath_e = XPath.newInstance("//Entry");
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 "";
}
}
public String getFedex_url()
{
return fedex_url;
}
public void setFedex_url(String fedex_url)
{
this.fedex_url = fedex_url;
}
public String getAccountNumber()
{
return AccountNumber;
}
public void setAccountNumber(String accountNumber)
{
AccountNumber = accountNumber;
}
public String getMeterNumber()
{
return MeterNumber;
}
public void setMeterNumber(String meterNumber)
{
MeterNumber = meterNumber;
}
public String getShipDate()
{
return ShipDate;
}
public void setShipDate(String shipDate)
{
ShipDate = shipDate;
}
public String getDropoffType()
{
return DropoffType;
}
public void setDropoffType(String dropoffType)
{
DropoffType = dropoffType;
}
public String getPackaging()
{
return Packaging;
}
public void setPackaging(String packaging)
{
Packaging = packaging;
}
public String getWeightUnits()
{
return WeightUnits;
}
public void setWeightUnits(String weightUnits)
{
WeightUnits = weightUnits;
}
}
三、USPS
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 USPS
{
private String usps_userid;
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;
private String xml_dest;
public USPS()
{
this.usps_userid = "123456789";
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 = "";
this.xml_dest = "http://production.shippingapis.com/shippingapi.dll";
}
@SuppressWarnings("unchecked")
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>";
WishBrowser wb = new WishBrowser(this.xml_dest);
wb.setCharSet("utf-8");
String strFile = wb.sendXmlRequest(strXML);
ByteArrayInputStream bis = new ByteArrayInputStream(strFile.getBytes());
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(bis);
XPath compPath = XPath.newInstance("//Error");
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());
SAXBuilder builder_e = new SAXBuilder();
Document doc_e = builder_e.build(bis_e);
XPath compPath_e = XPath.newInstance("//Package//Error");
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);
XPath compPath_e_e = XPath.newInstance("//Package//Postage");
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 "";
}
}
@SuppressWarnings("unchecked")
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 = "http://testing.shippingapis.com/ShippingAPITest.dll";
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 = "http://Production.ShippingAPIs.com/ShippingAPI.dll";
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>";
}
WishBrowser wb = new WishBrowser(xml_dest);
wb.setCharSet("utf-8");
String strFile = wb.sendXmlRequest(strXML);
ByteArrayInputStream bis = new ByteArrayInputStream(strFile.getBytes());
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(bis);
XPath compPath = XPath.newInstance("//Error");
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());
SAXBuilder builder_e = new SAXBuilder();
Document doc_e = builder_e.build(bis_e);
XPath compPath_e = XPath.newInstance("//Package//Service");
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());
SAXBuilder builder_e_i = new SAXBuilder();
Document doc_e_i = builder_e_i.build(bis_e_i);
XPath compPath_e_i = XPath.newInstance("//Package");
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 "";
}
}
public String getUsps_userid()
{
return usps_userid;
}
public void setUsps_userid(String usps_userid)
{
this.usps_userid = usps_userid;
}
public String getUsps_password()
{
return usps_password;
}
public void setUsps_password(String usps_password)
{
this.usps_password = usps_password;
}
public String getUsps_container()
{
return usps_container;
}
public void setUsps_container(String usps_container)
{
this.usps_container = usps_container;
}
public String getUsps_pkgsize()
{
return usps_pkgsize;
}
public void setUsps_pkgsize(String usps_pkgsize)
{
this.usps_pkgsize = usps_pkgsize;
}
public boolean isUsps_machinable()
{
return usps_machinable;
}
public void setUsps_machinable(boolean usps_machinable)
{
this.usps_machinable = usps_machinable;
}
public String getUsps_mailtype()
{
return usps_mailtype;
}
public void setUsps_mailtype(String usps_mailtype)
{
this.usps_mailtype = usps_mailtype;
}
public boolean isIs_canned_test()
{
return is_canned_test;
}
public void setIs_canned_test(boolean is_canned_test)
{
this.is_canned_test = is_canned_test;
}
public String getRESULT_uspsintl_Prohibitions()
{
return RESULT_uspsintl_Prohibitions;
}
public void setRESULT_uspsintl_Prohibitions(String prohibitions)
{
RESULT_uspsintl_Prohibitions = prohibitions;
}
public String getRESULT_uspsintl_Restrictions()
{
return RESULT_uspsintl_Restrictions;
}
public void setRESULT_uspsintl_Restrictions(String restrictions)
{
RESULT_uspsintl_Restrictions = restrictions;
}
public String getXml_dest()
{
return xml_dest;
}
public void setXml_dest(String xml_dest)
{
this.xml_dest = xml_dest;
}
}
四、Shipping.
public class Shipping
{
// 发货人州编码
private String shipperstateprovincecode;
// 发货人邮政编码
private String shipperpostalcode;
// 发货人国家地区编码
private String shippercountrycode;
// 发货人城市
private String shippercity;
private boolean USPS_ENABLED;
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.USPS_ENABLED = true;
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 = "";
String DeclaredValue = "0";
// UPS
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 (!fedex_fdxe_shipping_options.trim().equals(""))
{
if (!shipping_options.trim().equals(""))
{
shipping_options = shipping_options + "WISH_DELIM"
+ fedex_fdxe_shipping_options;
}
else
{
shipping_options = fedex_fdxe_shipping_options;
}
}
if (!fedex_fdxg_shipping_options.trim().equals(""))
{
if (!shipping_options.trim().equals(""))
{
shipping_options = shipping_options + "WISH_DELIM"
+ fedex_fdxg_shipping_options;
}
else
{
shipping_options = fedex_fdxg_shipping_options;
}
}
boolean skip_usps_domestic = false;
if (!receivercountrycode.trim().equals("")
|| !receivercountryname.trim().equals(""))
{
if (!receivercountrycode.toUpperCase().trim().equals("US")
&& !receivercountryname.toUpperCase().trim().equals("USA"))
{
skip_usps_domestic = true;
}
}
// USPS
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;
}
}
}
}
if (USPSINTL_ENABLED
&& !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;
}
}
}
shipping_options = shipping_options.replaceAll("\"", "");
// REMOVE UNWANTED OPTIONS BASED ON FILTER LIST
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");
}
public String getShipperstateprovincecode()
{
return shipperstateprovincecode;
}
public void setShipperstateprovincecode(String shipperstateprovincecode)
{
this.shipperstateprovincecode = shipperstateprovincecode;
}
public String getShipperpostalcode()
{
return shipperpostalcode;
}
public void setShipperpostalcode(String shipperpostalcode)
{
this.shipperpostalcode = shipperpostalcode;
}
public String getShippercountrycode()
{
return shippercountrycode;
}
public void setShippercountrycode(String shippercountrycode)
{
this.shippercountrycode = shippercountrycode;
}
public String getShippercity()
{
return shippercity;
}
public void setShippercity(String shippercity)
{
this.shippercity = shippercity;
}
public boolean isUSPS_ENABLED()
{
return USPS_ENABLED;
}
public void setUSPS_ENABLED(boolean usps_enabled)
{
USPS_ENABLED = usps_enabled;
}
public boolean isFEDEX_FDXE_ENABLED()
{
return FEDEX_FDXE_ENABLED;
}
public void setFEDEX_FDXE_ENABLED(boolean fedex_fdxe_enabled)
{
FEDEX_FDXE_ENABLED = fedex_fdxe_enabled;
}
public boolean isFEDEX_FDXG_ENABLED()
{
return FEDEX_FDXG_ENABLED;
}
public void setFEDEX_FDXG_ENABLED(boolean fedex_fdxg_enabled)
{
FEDEX_FDXG_ENABLED = fedex_fdxg_enabled;
}
public boolean isUPS_ENABLED()
{
return UPS_ENABLED;
}
public void setUPS_ENABLED(boolean ups_enabled)
{
UPS_ENABLED = ups_enabled;
}
public boolean isUSPSINTL_ENABLED()
{
return USPSINTL_ENABLED;
}
public void setUSPSINTL_ENABLED(boolean uspsintl_enabled)
{
USPSINTL_ENABLED = uspsintl_enabled;
}
public boolean isSHOW_UPS_ERROR()
{
return SHOW_UPS_ERROR;
}
public void setSHOW_UPS_ERROR(boolean show_ups_error)
{
SHOW_UPS_ERROR = show_ups_error;
}
public boolean isSHOW_FEDEX_ERROR()
{
return SHOW_FEDEX_ERROR;
}
public void setSHOW_FEDEX_ERROR(boolean show_fedex_error)
{
SHOW_FEDEX_ERROR = show_fedex_error;
}
public boolean isSHOW_USPS_ERROR()
{
return SHOW_USPS_ERROR;
}
posted on 2008-07-26 08:42
licy 阅读(2727)
评论(0) 编辑 收藏