Created
October 1, 2012 10:26
-
-
Save joncalhoun/3810769 to your computer and use it in GitHub Desktop.
Buy postage with Easy Post and Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EasyPost.setApiKey("ek_0HbTD15HeT6RFTwCKoUQ7rrB2NzMZ"); | |
// Create the package | |
EasyPost.Package package = new EasyPost.Package() | |
.setWeigth(1.1) | |
.setHeight(12) | |
.setWidth(14) | |
.setLength(7); | |
// Create the to and from addresses | |
EasyPost.Address toAddress = new EasyPost.Address() | |
.setName("Reed Rothchild") | |
.setStreet1("101 California St") | |
.setStreet2("Suite 1290") | |
.setCity("San Francisco") | |
.setState("CA") | |
.setZip("94111"); | |
EasyPost.Address fromAddress = new EasyPost.Address() | |
.setName("Dirk Diggler") | |
.setStreet1("300 Granelli Ave") | |
.setCity("Half Moon Bay") | |
.setState("CA") | |
.setZip("94019"); | |
// Create the request for postage | |
EasyPost.PostageRequest pr = new EasyPost.PostageRequest() | |
.setTracking(true) | |
.setInsurance(true) | |
.setPackage(package) | |
.setTo(toAddress) | |
.setFrom(fromAddress) | |
// Optionally | |
.setDescription("Postage for VHS of Boogie Nights") | |
.setExternalId("31224974"); // The ID of the order in your own DB. | |
// Purchase the postage | |
EasyPost.Postage.buy(pr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment