public Message RetrieveMessage(String value, Filter filter, Order order, boolean delete) 
			throws IOException, QueueInexistentException, ClientInexistentException, UnspecifiedErrorException, InvalidHeaderException {
		this.sendMessage(new RetrieveMessageRequest(value, filter, order, delete));

		ProtocolMessage message = this.getResponse();

		if (message.getMessageType() == MessageType.REQUEST_RESPONSE) {
			RequestResponse rqMessage = (RequestResponse) message;
			
			switch (rqMessage.getStatus()) {
			case NO_MESSAGE:
				return null;
			case QUEUE_NOT_EXISTS:
				if (filter == Filter.QUEUE) throw new QueueInexistentException(value);
				else throw new UnexpectedResponseException();
			case NO_CLIENT:
				if (filter == Filter.SENDER) throw new ClientInexistentException(value);
				else throw new UnexpectedResponseException(); 
			case EXCEPTION:
				throw new UnspecifiedErrorException();
			default:
				throw new UnexpectedResponseException();
			}
			
		} else {
			RetrieveMessageResponse response = (RetrieveMessageResponse) message;

			return new Message(response.getMessageId(), response.getContext(), (byte)response.getPriority(),
					response.getMessageContent(), response.getSender(), response.getReceiver(), response.getQueue());
		}
	}