In other cases, it is possible to be denied a position as you have a criminal record. This may come about if the job involved a criminal record check and you have a criminal record. If this is the case, you can write a letter of appeal to see if this was the reason or whether it was something else.
Many jobs also do drugs tests, if you fail these there is also a possibility you will not get a job. Drugs tests are becoming increasingly common in job interview situations as employees want to know if the person they are employing has a drug issue. Even recreational drug use will be the cause of a failure of one of these tests.
To write a letter, make sure it is clear and polite. Question why you didn't get the job and what issues may have caused this. Don't be rude and make sure to address the person by the proper title as you never know if you will be called back if another position becomes available.
If you get a reply that is not a suitable or legal reason, it is possible to go to your solicitor to discuss a grievance procedure and see can you sort out some form of compensation.
There is no precise way of writing a letter, just remember to be respectful, clear and concise when writing the letter.