The Rambam in his laws of giving to the poor answers this question by outlining eight degrees of preference in giving charity. They are as follows, with #1 being the most preferable and #8 and proceeding in order of more to less preferable:
1. Helping the recipient to become self-supporting through charity, partnership or a loan.
2. Giving charity while the giver’s and receiver’s identities remain hidden from each other.
3. Giving while hiding the identity of the giver from the receiver.
4. Giving while the receiver’s identity is hidden, but the giver’s identity is known to the recipient.
5. Giving without being asked.
6. Giving when being asked.
7. Giving graciously, but less than one should.
8. Giving reluctantly.
In addition, it is important to consider which recipients are preferable. Following are some guidelines:
Non-Jews. The Rambam quotes several verses from the Torah at the beginning of his laws on giving to the poor. Not all of these deal exclusively with Jews. The Minchat Chinuch derives from this that giving to non-Jews is also part of the Torah mitzvah of tzedakah, but giving to a Jew in need is preferable and has a greater emphasis in the Torah. In addition, giving charity to non-Jews was encouraged by the Rabbis in order to maintain positive relations with other peoples.
Family. It is preferable to help those in need who are closest to the giver. The giver’s family and home-town are preferable. The people of Jerusalem also have a preferred status.
Defining poverty. The Talmud leaves the definition of the needs of the recipient very broad. There is a principle of “Dei mechsoro”, meeting the needs of the individual case. This depends on the recipient’s previous and expected life-style.