Java: Cancel Delivery Of A Letter with CancelDelivery()

Download Download our Java samples from this page. Find this sample in directory /test/com/postalmethods/client

package com.postalmethods.client;
 
import static org.junit.Assert.*;
 
import org.junit.Before;
import org.junit.Test;
 
import com.postalmethods.client.api.CancelDeliveryResponse;
import com.postalmethods.client.api.SendLetterResponse;
 
public class CancelDeliveryTest {
 
    private PostalMethodsClient client;
    private int letterId;
 
    @Before
    public void setUp() {
 
        client = new PostalMethodsClientFactory().build(TestConstants.USERNAME, TestConstants.PASSWORD);
 
        // Send a sample letter so we have a letterId to check status on.
        SendLetterResponse sendResponse = client.sendLetter("Junit test letter", TestConstants.SAMPLE_LETTER_FILENAME);
        int code = sendResponse.getResult().getCode();
        assertTrue(code > 0 );
        this.letterId = code;
    }
 
    @Test
    public void testGetLetterStatus() {
 
        System.out.println("Making call to CancelDelivery...");
        CancelDeliveryResponse response = client.cancelDelivery(letterId);
        int code = response.getResult().getCode();
        System.out.println("Service call completed:\n" + response.getResult().toString());
        assertEquals(-3000,code); // success
    }
}