Java: Send A Letter with SendLetterAndAddress()

Download Download Java samples [.zip]. Find this sample in directory /test/com/postalmethods/client

This sample demonstrates how to send a letter through PostalMethods using the Address Outside method.

package com.postalmethods.client;
 
import static org.junit.Assert.assertTrue;
 
import org.junit.Before;
import org.junit.Test;
 
import com.postalmethods.client.api.SendLetterAndAddressResponse;
import com.postalmethods.client.model.Address;
 
 
public class SendLetterAndAddressTest {
 
    private PostalMethodsClient client;
 
    @Before
    public void setUp() {
        client = new PostalMethodsClientFactory().build(TestConstants.USERNAME, TestConstants.PASSWORD);
    }
 
    @Test
    public void testSendLetterAndAddress() {
 
        Address address = new Address(
                "Accounting Dept.",
                "c/o Andrea Smith",
                "",
                "ACME Inc.",
                "100 Flower Street.",
                "suite 100",
                "Los Angeles",
                "CA",
                "90010",
                "USA");
        String description = "Test letter with address.";
 
        System.out.println("Making call to SendLetter...");
        SendLetterAndAddressResponse response = client.sendLetterAndAddress(description, TestConstants.SAMPLE_LETTER_FILENAME, address);
        System.out.println("Service call completed:\n" + response.getResult().toString());
 
        int code = response.getResult().getCode();
        assertTrue(code > 0 );
 
        System.out.println("New letter id is: " + code);
    }
}